<template>
  <div id="app">
    <router-view />
  </div>
</template>

<script setup>
import { onMounted, onUnmounted } from 'vue'
import { useAuthStore } from './stores/auth'
import { useMessageStore } from './stores/message'
import { useRouter } from 'vue-router'

const authStore = useAuthStore()
const messageStore = useMessageStore()
const router = useRouter()

onMounted(() => {
  // 监听通知点击事件
  if (window.electronAPI) {
    window.electronAPI.onNotificationClicked((event, messageId) => {
      router.push(`/message/${messageId}`)
    })

    window.electronAPI.onNavigateTo((event, path) => {
      router.push(path)
    })
  }

  // 自动登录检查
  authStore.checkAutoLogin()
})

onUnmounted(() => {
  if (window.electronAPI) {
    window.electronAPI.removeAllListeners('notification-clicked')
    window.electronAPI.removeAllListeners('navigate-to')
  }
})
</script>

<style lang="scss">
#app {
  height: 100vh;
  overflow: hidden;
}
</style>